

<<<<<<< HEAD

=======
let pageSize = 2;
let currentPage = 1;
let totalPage;
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
addgl();
addgldel();
xgfanHuiBut();
addFaHuoXinXi();
fanHuiBut();
AddUserInfor();
changeEveryoneBut();
changeInforBut();
// AddPageEvent();
// BindPage();
tjchongzhi();
xgchongzhi();
producePage(juese); 
<<<<<<< HEAD
// addPageEvent();
// pageup();
// pagedown();
pagenumerevent("#pagUp");
pagenumerevent("#pagDow");
//渲染页面
function addgl(juese,pageSize,currentPage){
=======
addPageEvent();
pageup();
pagedown();
//渲染页面
function addgl(){
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
    $("#glTable").html("");
    let start = (currentPage - 1)*pageSize;
    let end = currentPage*pageSize;
    for(var i = start;i<end&&i<juese.length;i++){
        $("#glTable").append(`
        <tr>
            <td><input type="checkbox" class="cbxItem" value="${juese[i].ID}"></td>
            <td>${juese[i].ID}</td>
            <td>${juese[i].juesename}</td>
            <td>${juese[i].paixu}</td>
            <td>
                <!-- 修改图标 -->
                <button id="xg"  type="button" gl-xg="${juese[i].ID}" class="layui-btn layui-btn-sm"><i class="layui-icon"></i></button>
                <!-- 删除图标 -->
                <button id="cc" type="button" gl-id="${juese[i].ID}" class="layui-btn layui-btn-normal layui-btn-sm" style="background-color: red;"><i class="layui-icon"></i></button>
            </td>
        </tr>
       `)
    }
}


//点击删除的弹出框的点击事件
function addgldel(){
$("#glTable").on("click","#cc",function(){
<<<<<<< HEAD
    let pageSize = 5; //每页显示条数
    let TotalPage = Math.ceil(juese.length / pageSize);
    for(let i=0;i<TotalPage;i++){
        let Addstorea=$(".pageBut").eq(i).attr("class");
        let Addas=Addstorea.split(" ");
        if(Addas[1]=="cyan") {
           var pagesname= $(".pageBut").eq(i).html();
        }
    //    console.log(Addas); 
    }
=======
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
let id = $(this).attr("gl-id");//获取点击哪行的id

layer.confirm('确认删除？', {
    btn: ['确认','取消'] //按钮
    
  }, function(){    
    layer.msg('已删除', {icon: 1,time:500});
    gldel(id);
    producePage(juese); 
<<<<<<< HEAD
    addgl(juese,pageSize,pagesname);
=======
    addgl();
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
  })
})

}
//删除的方法
function gldel(id){
  for(i = 0;i<juese.length;i++){
         if(juese[i].ID==id){
            juese.splice(i,1);
            break;
         }
  }
}
// function xggl(){
// $("#glTable").on("click","#xg",function(){
//     //  window.location.href="yunying-guanlixg.html"
//      let id = $(this).attr('gl-xg');
//         console.log(id)
//     var obj = guanliyuan.find(v => v.ID == id);
//     $(".glusername").val(obj.glusername);
//     console.log($(".glusername").val(obj.glusername));
// })
// }
$("#cbxAll").click(function () {
    //获取全选checkbox的状态
    let state = $("#cbxAll").prop("checked");
   //将每一项数据前的checkbox改成和全选checkbox一样的状态
    $(".cbxItem").prop("checked",state);
})

function checkAllChecked() {
    if($(".cbxItem:not(:checked)").length==0){ //没有选中的个数
        $("#cbxAll").prop("checked",true);
    }else{
        $("#cbxAll").prop("checked",false);
    }
}

$("#glTable").on("click",".cbxItem",function(){
    checkAllChecked();
})
//批量删除
$("#DIB").click(function(){  
<<<<<<< HEAD
    let pageSize = 5; //每页显示条数
    let TotalPage = Math.ceil(juese.length / pageSize);
    for(let i=0;i<TotalPage;i++){
        let Addstorea=$(".pageBut").eq(i).attr("class");
        let Addas=Addstorea.split(" ");
        if(Addas[1]=="cyan") {
           var pagesname= $(".pageBut").eq(i).html();
        }
    //    console.log(Addas); 
    }
=======

>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        // if(layer.confirm('确认删除？', {
        //     btn: ['确认','取消'] //按钮
            
        //   })){  
    
         var checks = $(".cbxItem:checked");      
    
        if(checks.length == 0){ 
            alert('未选中任何项！');
            return false;
        }        
        // layer.confirm('确认删除？', {
        //     btn: ['确认','取消'] //按钮
            
        //   })
       //将获取的id值存入数组       
        var checkData = new Array();    
         checks.each(function(){        
                   checkData.push($(this).val());//获取选中的ID
        });  
         for(var i = 0;i<juese.length;i++){//遍历数组
             console.log(juese[i]);
             for(var j = 0;j<checkData.length;j++){
                console.log(checkData[j]);
                if(juese[i].ID==checkData[j]){//如果id相同就删除
                    juese.splice(i,1);
                }
             }
         }
         checkAllChecked();
         producePage(juese); 
<<<<<<< HEAD
         addgl(juese,pageSize,pagesname);  
=======
         addgl();  
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        
    //  }   
    });
    //添加数据 按钮添加事件
function addFaHuoXinXi(){
        $("#addbtn").click(function(){
            $("#juesename").val("");
            $("#paixu").val("");
            $("#show").hide();
            $("#tanchukuang").show();
            // $("#xiugaikuang").hide();
        })
    }
    //添加数据界面的返回按钮
function fanHuiBut(){
        $("#backBut").click(function(){
            $("#show").show();
            $("#tanchukuang").hide();
        })  
    }    
//添加数据
function AddUserInfor(){
        $("#tijiao").click(function(){
<<<<<<< HEAD
            let pageSize = 5; //每页显示条数
            let TotalPage = Math.ceil(juese.length / pageSize);
            for(let i=0;i<TotalPage;i++){
                let Addstorea=$(".pageBut").eq(i).attr("class");
                let Addas=Addstorea.split(" ");
                if(Addas[1]=="cyan") {
                   var pagesname= $(".pageBut").eq(i).html();
                }
            //    console.log(Addas); 
            }
=======
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        //   var ID = $("#iD").val();    //id内容
          var juesename = $("#juesename").val();//获取
          var paixu = $("#paixu").val();
          if(juesename == '' || paixu == ''){
            layer.msg("请填写完整", { icon: 52, time: 500 });
          }else{
            var newShuZu = {ID:juese[juese.length-1].ID+1,juesename:juesename,paixu:paixu};
            juese.push(newShuZu);
              $("#tanchukuang").hide();
              $("#show").show();
              producePage(juese); 
<<<<<<< HEAD
              addgl(juese,pageSize,pagesname); 
=======
              addgl(); 
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
          }
          
        })
    }
//获取数据
function changeEveryoneBut(){
<<<<<<< HEAD
=======
        
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
    $("#glTable").on("click","#xg",function(){
        //  window.location.href="yunying-guanlixg.html"
        id = $(this).attr('gl-xg');
            console.log(id)
        var obj = juese.find(v => v.ID == id);
        $("#xgjuesename").val(obj.juesename);
        $("#xgpaixu").val(obj.paixu);
        $("#show").hide();   //主界面隐藏
        $("#xiugaikuang").show();   //修改界面出现
    })
 }
 
 function xgfanHuiBut(){
    $("#xgbackBut").click(function(){
        $("#show").show();
        $("#xiugaikuang").hide();
    })  
}  
//确认修改信息按钮
 function changeInforBut(){
        $("#xiugai").click(function(){
<<<<<<< HEAD
            let pageSize = 5; //每页显示条数
            let TotalPage = Math.ceil(juese.length / pageSize);
            for(let i=0;i<TotalPage;i++){
                let Addstorea=$(".pageBut").eq(i).attr("class");
                let Addas=Addstorea.split(" ");
                if(Addas[1]=="cyan") {
                   var pagesname= $(".pageBut").eq(i).html();
                }
            //    console.log(Addas); 
            }
=======
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        let xgjuesename = $("#xgjuesename").val(); 
        let xgpaixu = $("#xgpaixu").val();   
        for(var i=0;i<juese.length;i++){
                 if(juese[i].ID == id){
                    juese[i].ID = juese[i].ID;  //将当前数组中的id改为输入框中的id                    
                    juese[i].juesename = xgjuesename;   
                    juese[i].paixu = xgpaixu; 
            }
          }
          // console.log(faHuoXinXiArr[XG]);
           $("#show").show();   //主界面隐藏
            $("#xiugaikuang").hide();   //修改界面出现
<<<<<<< HEAD
            addgl(juese,pageSize,pagesname);
=======
            addgl();
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        })
    }
function tjchongzhi(){
        $("#tjchongzhi").click(function(){
            $("#juesename").val("");
            $("#paixu").val("");
        })
    }
function xgchongzhi(){
        $("#xgchongzhi").click(function(){
            $("#xgjuesename").val("");
            $("#xgpaixu").val("");
        })
    }

<<<<<<< HEAD
// 创建页数
function producePage(page){
    let pageSize = 5;
let currentPage = 1;
let totalPage = Math.ceil(page.length/pageSize);   //总页数等于总条数/每页的条数
=======
// function BindPage(){
//     TotalPage = Math.ceil(juese.length/pagerSize);
//     currentPage = currentPage>TotalPage?TotalPage : currentPage;
//     $("#test1").html(" ");
//     for(var i = 1 ;i<=TotalPage;i++){
//       $("#test1").append(`<button>${i}</button>`);
//     }

// }
// function AddPageEvent(){
//     $("#test1").on("click","button",function(){
//     currentPage =parseInt($(this).text());
//     addgl();
//     })
// }
// 创建页数
function producePage(page){
    totalPage = Math.ceil(page.length/pageSize);   //总页数等于总条数/每页的条数
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
    currentPage = currentPage > totalPage?totalPage : currentPage ;   //当前页
    //生成对应的页码
    $("#test1").html("");   //先将页码清空
    for(var i=1;i<=totalPage;i++){
        $("#test1").append(`
            <button class="pageBut">${i}</button>
        `)
<<<<<<< HEAD
    
    $('.pageBut').eq(0).addClass("cyan").siblings().removeClass("cyan");
    addgl(juese,pageSize,currentPage);
}
addPageEvent()
=======
    }
    $('.pageBut').eq(0).addClass("cyan").siblings().removeClass("cyan");
}
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
//给页码按钮添加事件
function addPageEvent(){
    $("#piLiangAndFenYe").on("click",".pageBut",function(){
        currentPage = parseInt($(this).text()); 
        $(this).addClass("cyan").siblings().removeClass("cyan");   
        console.log(currentPage);   
<<<<<<< HEAD
        addgl(juese,pageSize,currentPage);
    })}
}
//上下页
function pagenumerevent(pagenuber) {
    let pageSize = 5; //每页显示条数
    let totalPage = Math.ceil(juese.length / pageSize);
    for(let i=0;i<totalPage;i++){
        let Addstorea=$(".pageBut").eq(i).attr("class");
        let Addas=Addstorea.split(" ");
        if(Addas[1]=="cyan") {
           var currentPage= $(".pageBut").eq(i).html();
        }
    //    console.log(Addas); 
    }
    $(pagenuber).click(function() {
        if (pagenuber == '#pagDow') {
            if (currentPage <= 1) {
                currentPage = 1;
                $('.pageBut').eq(0).addClass("cyan").siblings().removeClass("cyan");
            }else{
                currentPage--;
            }
            
            console.log(currentPage);
            for (let i = 0; i <=totalPage; i++) {
                let buttoncontent = parseInt($('.pageBut').eq(i).text());
                if (buttoncontent == currentPage) {
                    $('.pageBut').eq(i).addClass("cyan").siblings().removeClass("cyan");
                }
            }
            addgl(juese,pageSize,currentPage);
        } else if (pagenuber == '#pagUp') {
            let totalPage = Math.ceil(juese.length / pageSize);
            console.log(pageSize);
            if (currentPage == totalPage) {
                    currentPage = totalPage;
                    console.log(currentPage);
                }else{
                    currentPage++;
                }
            
            console.log(currentPage);
            for (let i = 0; i <=totalPage; i++) {
                let buttoncontent = parseInt($('.pageBut').eq(i).text());
                if (buttoncontent == currentPage) {
                    $('.pageBut').eq(i).addClass("cyan").siblings().removeClass("cyan");
                }
            }
            addgl(juese,pageSize,currentPage);
=======
        addgl();   
    })
}
function pageup(){
    $("#pagUp").click(function(){
        currentPage++;
        producePage(juese); 
        addgl();  
    })
}
function pagedown(){
    $("#pagDow").click(function(){
        if(currentPage>=2){
            currentPage--;
            producePage(juese); 
            addgl();  
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        }
        
    })
}